home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS02.ADF / Tutorials / Animate < prev    next >
Text File  |  1989-05-30  |  13KB  |  283 lines

  1.  
  2. TITLE: GELS and Sprites
  3.  
  4. ON SPRITES, BOBS AND GELS -- John T. Draper (Captain Crunch)
  5.  
  6.    Last time,  I covered an overview on sprites, Bobs and Gels.   Now I'm 
  7. going to show how they are all related.
  8.  
  9.    On the lowest level,  there are 8 hardware sprite generators.  These are 
  10. hardware components which are controlled by storing data into registers. Each 
  11. sprite is 16 pixels wide,  and can be any height.   Normally, you don't have 
  12. to worry about  directly controlling the hardware sprites.   There are 
  13. routines in "graphics.library" called VSprites ( Virtual sprites ) which 
  14. control the hardware sprites.   This, in effect, appears that you have an 
  15. unlimited set of sprites with which to work.
  16.  
  17.    There are certain restrictions which apply to the use of these sprites. 
  18. You can only have four sprites across a scan line at any one time. As the 
  19. lines are scanning across the screen,  they eventually will scan across where 
  20. a sprite is to be placed.  In order to efficiently use the hardware sprite 
  21. generator,  the sprites MUST be in a certain order.
  22.  
  23.     -----------------      <-- Sprite A gets grabbed as scanline reaches it
  24.     |               |
  25.     |               |
  26.     |  sprite A     |        -----------------   <-- Sprite B gets grabbed
  27.     |               |        |               |       Now there are 2 sprites
  28.     |               |        |               |       in use.
  29.     |               |        |   sprite B    |
  30.     -----------------        |               |   <-- Sprite A gets released
  31.                              |               |       Now there is ONE sprite.
  32.                              |               |       in use.
  33.                              |               |
  34.                              -----------------   <-- Now sprite B gets released 
  35.  
  36.     If you are stealing hardware sprites,  you are effectively stealing two 
  37. (even-odd) sprite pairs.  0/1,  2/3,   4/5,   and  6/7,  which share the same 
  38. color registers.   So,  IF you are working at this low level,  you should 
  39. grab a pair of sprites.   Because you are not granted exclusive use of the 
  40. color registers and the hardware sprites,  you should release the sprites 
  41. immediately.   Remember!!  You normally WON'T be working at this low level, 
  42. but it's important that you understand it so you can deal with the 
  43. limitations. Example code on page 9-11 in the Rom Kernal manual shows the use 
  44. at this low level.   I Caution you that this code WON'T work the way it's 
  45. written,  but shows you an idea how to handle the simple sprites.
  46.  
  47.    The relationships between simple sprites, Vsprites,  Bobs, and Gels are as 
  48. follows.   Lets start at the highest level this time and work down to the 
  49. simple sprite.
  50.  
  51.    Any object on the screen such as the robots in "Robot city" are called 
  52. GELS. (Graphic ELementS ).   A GEL can be a man walking across the screen and 
  53. includes ALL positions of the animated man.
  54.  
  55.    Included within a GEL is an AnimOB (animated object), which comprises of a 
  56. series of AnimComp's or each animated "Position" or "Frame" of the object. 
  57. These frames are linked together in a linked list which are handled by the 
  58. "Exec" or multi-tasking system.   Again, they have to be in some kind of 
  59. order.
  60.  
  61.    AnimComps are animated components which are an expansion of the Bob.  A 
  62. Bob (Blitter OBject) is an extension of the Vsprite.   It uses a combination 
  63. of the simple sprites (Hardware),  and "Blitter" (A fast memory move engine 
  64. implemented in hardware),  to "Stamp" the sprite on the screen using the 
  65. video co-processor called the "Copper".
  66.  
  67.   Each "level",  from the simple sprite to the GEL uses their own data 
  68. structure which links to the other data structures.   Some people were making 
  69. comments about why the RastPort and the Viewports weren't combined into ONE 
  70. structure.   I would assume they (Amiga) wanted to keep every level separate. 
  71. Links do this nicely.
  72.  
  73. DISPLAYING VSPRITES
  74. -------------------
  75.  
  76. Here is a quick summary of what it takes to display Vsprites and/or Bobs.
  77.  
  78. o Define a View structure by opening up a screen and/or a window.  Using 
  79.   OpenScreen then OpenWindow (Optional) from intuition.
  80.  
  81. o Specify the RGB Colors registers for the Viewport, using: 
  82.   SetRGB4(&Viewport, num, r, g, b),  
  83. where: num = Color number from 0 to 31 
  84. r = Red level g = green level b = blue level.
  85.  
  86. Normally, the Preferences program sets this up.  This is OPTIONAL.
  87.  
  88. o Allocate memory for your borderline bitplanes.  Also Allocate memory to 
  89.   store the image behind the sprites,  and other necessary bit images.
  90.  
  91. o Initialize the GELS, by calling:  InitGels(&spriteA, &SpriteB, &Gelsinfo)
  92.   spriteA - Pointer to the Vsprite structure used as list head.
  93.   spriteB - Pointer to the Vsprite structure used as list tail.
  94.   Gelsinfo - Pointer to the GELSInfo structure to be initialized.
  95.  
  96. o Define the sprite(s)
  97.   - Height(s)
  98.   - Onscreen Position(s)
  99.   - Where to find Image data
  100.   - Where to find SprColors to use
  101.   - Set up Vsprite structure flags that show this is Vsprite.
  102.   - Set MUSTDRAW (A flag) if it MUST be drawn.
  103.  
  104. o Add the Vsprite to the GEL list.  Call:  AddVSprite(VS, RPort)
  105.   VS = Pointer to Vsprite structure.   IE: Vsprite *VS
  106.   RPort = Pointer to a Rastport Structure.
  107.  
  108. o Change (Or set) the VSprite appearance by changing pointer to the Image data
  109.   and its height.  This is done by accessing Imagedata and SprColors fields
  110.   in the Vsprite structure.   If VS is a pointer to a Vsprite structure,  then:
  111.  
  112.   VS->ImageData = &MynewData   Where MynewData points to the new data.
  113.   VS->SprColors = &MyColors    Where MyColors points to new "data" colors.
  114.  
  115. o Move the sprite by defining a new Y,X Position.  If VS is a pointer to
  116.   the VSprite structure,  then:
  117.  
  118.   VS->X = 23
  119.   VS->Y = 45
  120.  
  121.   Sets the position to 23, 45.   You also can look at the previous position
  122.  
  123.   Prevx = VS->OldX
  124.   Prevy = VS->OldY
  125.  
  126. o Now you can display the Vsprites with this sequence of routines.
  127.  
  128.   ON_DISPLAY;   <-- Enables the system direct memory access to Playfield
  129.                     display.
  130.  
  131.   ON_SPRITE;    <-- Enables system DMA for access to Vsprites.
  132.  
  133.   SortGList(&rastport);  <-- Sorts the GELS in order for efficient access.
  134.  
  135. DrawGList(&rastport, &viewport);  <-- Looks through sorted list, Prepares 
  136.   necessary instructions and memory areas to display the data.  DOES NOT 
  137.   ACTUALLY DRAW ANYTHING ON SCREEN,  It draws into the RastPort.
  138.  
  139.   MrgCop(&myview);  <-- Merge together "Copper" instructions.
  140.  
  141.   LoadView(&myview) <-- Executes the "Copper" instructions as layed out in
  142.     the previous function.   THIS ACTUALLY DISPLAYS THE SPRITES.
  143.  
  144. There is a lot of clean-up to do when done with your program.  You must 
  145. release the memory used by your buffers by de-allocating them.  Remember to 
  146. CloseScreen, and CloseWindow (If you opened one). 
  147. }
  148.  
  149.  
  150. Name: BLITTER TUTORIAL
  151. Type: DOCUMENT
  152. Date: 7-NOV-1985 22:02 by CRUNCH
  153. Size: 5537
  154.  
  155. This is a tutorial on the Blitter and Amiga Animation.  it explains some of the
  156. blitter features, and the functions performed.
  157.  
  158. Keywords: GENERAL, BLITTER, ANIMATION, CRUNCH, DRAPER
  159.  
  160. ACTION> (Next, Down, Xm, List) list
  161. TITLE: Blitter, Sprites, and animation
  162.  
  163. AMIGA BLITTER AND SPRITES
  164. -------------------------
  165.  
  166.         Starting from the hardware and working up into "Intuition",  here is 
  167. a quick summary on how everything is put together.
  168.  
  169.         The Amiga has a high performance graphics engine that uses up to four 
  170. DMA channels.   This is the foundation for a higher level animation system. 
  171. Once the blitter registers are set up,  data copying and line drawing are 
  172. done in hardware and independently of the 68000 CPU.   Below is a quick 
  173. summary of blitter features and the operations they perform:
  174.  
  175. ** DATA COPYING - of bit plane images anywhere
  176.  
  177. ** MULTIPLE SOURCES - Up to 3 sources of data can be processed,  and then
  178.         the results can be placed in a destination area.
  179.  
  180. ** LOGIC OPERATIONS - Up to 256 logic operations on the 3 data sources can be
  181.         performed.
  182.  
  183. ** MULTIPLE MODULOS - For each of the sources which allow data to be moved
  184.         to and from identical rectangular windows within different sizes of
  185.         larger playfield images.
  186.  
  187. ** ASCENDING AND DESCENDING ADDRESSES - Bottom to top and vice versa.
  188.  
  189. ** SHIFTING - Up to 15 bits is permitted before applying the logic operations.
  190.  
  191. ** MASKING - The leftmost and rightmost data word can be masked which allow
  192.         operations on bit-boundarys.
  193.  
  194. ** ZERO DETECTION - Used for collision detection, because the results of the
  195.         logic operations can be sensed.
  196.  
  197. ** AREA FILLING - Between pre-drawn lines.
  198.  
  199. ** LINE DRAWING - At any angle.
  200.  
  201.         The "blitter" is very efficient at copying such blocks because it 
  202. only needs to be told the starting address, Dest address, and the size of the 
  203. block. It is important to note that the addresses MUST be within the FIRST 
  204. 512k section of memory.  I am not certain if the Lattice C compiler is smart 
  205. enough to place code outside of that area, thus freeing that special addess 
  206. space for larger programs.  When the memory moves are complete, the processor 
  207. is signaled with a flag and an interrupt.
  208.  
  209.         Listed in the Hardware manual is a set of logical formulas (There are 
  210. lo to achieve just about any logical operations on the pixels.   The SPRITE 
  211. generator uses the "blitter" hardware to generate sprites, icons, and the 
  212. other graphics objects.
  213.  
  214.         Blitter uses "modulos" to allow manipulation of smaller images within 
  215. la images.   There are four modulos in the Blitter.  This allows all three 
  216. sources, and the dest to each have different sizes.
  217.  
  218.         On top of this hardware foundation are the Sprites.  Normally,  
  219. "blitter is controlled from a higher level using a data structure called a 
  220. "blitter-node" The system can link these together into a FIFO queue.  When 
  221. your turn comes up to process an object, sprite or whatever,  your own 
  222. routine can be repeatedly called until your routine says its finished using 
  223. the blitter.
  224.  
  225.         There are actually 2 separate queues formed.  One called QBlit,  
  226. which is used when you want something done, and don't care when it happens,  
  227. and the other QBSBlit which means "queue beam synchronized" blitter 
  228. operations.   This beam synch takes precedence over the simple FIFO.
  229.  
  230.         The bltnode data structure is:
  231.  
  232.         struct  bltnode
  233.         {
  234.                 struct  bltnode *n;             /* Pointer to next bltnode
  235.                 int             (*function)();  /* Address of function when its
  236.                 char    stat;                   /* whether or not to "clean up"
  237.                 short   beamsync;               /* VBEAM counter value
  238.                 int             (*cleanup)();   /* Your clean-up function
  239.         };
  240.  
  241. SHORT INTRO TO animaTION
  242. ------------------------
  243.  
  244.         Here is a short intro to the animation routines available on the 
  245. Amiga. I won't go into detail because it's already about 3:30 am, So I will 
  246. briefly cover it.   You can mail me if you want more details.   Basically, 
  247. the animation routines let you define images called GELS (Graphic ELements).  
  248.  Each GEL has the following characteristics:
  249.  
  250. ** Height
  251. ** Width
  252. ** colors
  253. ** shape
  254. ** Position in the drawing area
  255. ** How to draw it
  256. ** How to move it
  257. ** How it interacts with other elements.
  258.  
  259.         Before you can use GELS, you must have prepared a VIEWPORT as 
  260. described in an earlier article.   Then you call:  InitGels();  This sets up 
  261. two "dummy VSPrites" which are used as the "head" and "tail" elements in the 
  262. system list of GELS.   You can the ADD and DELETE your GELS from this list.
  263.  
  264.         There are two types of animation one can perform on the AMiga.
  265.  
  266. ** Sprite animation - Sprites are 16 pixels wide, and as high as you like. 
  267.         Check out "robot city" and examine the screen carefully.
  268.  
  269. ** Playfield animation - is a technique one can use to modify sections of a 
  270.         background area (Playfield).   "Blitter" does the dirty work.
  271.  
  272.         This is a brief overview of the animation software,   there is more of
  273. course,  but this can give you an idea of what to expect.   There are simple
  274. sprites,  Vsprites, Bobs (Blitter Objects), AnimCOmps, and AmimObs and each has
  275. its own data structure or is the part of larger structures.
  276.  
  277.         For example:  MoveSprite (viewport, sprite, x, y);  Moves the sprites
  278. in any direction.  In the ROM Kernal manual (Where most of this info was
  279. derived) there are source code examples in C which describe how to control the
  280. sprites, GELS and other objects.
  281.  
  282.  
  283.